import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-07-29
 * Time:1:38
 */
@WebServlet("/refresh")
public class getTime extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
//        设置每秒刷新一次页面
        resp.setHeader("Refresh","1");
//        获取当前的时间
        Date now = new Date();
//        设置时间显示格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
        resp.getWriter().write("time" + simpleDateFormat.format(now));
    }
}
